package cn.faifai.desktop;

import cn.faifai.desktop.config.TrayManager;
import cn.faifai.desktop.events.listener.StageCloseListener;
import cn.faifai.common.utils.SpringContextUtil;
import cn.faifai.desktop.utils.StageManager;
import cn.faifai.desktop.utils.VirtualThreadPoolManager;
import cn.faifai.desktop.view.dialog.FileTaggingDialog;
import cn.faifai.desktop.view.MainView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class faifaiTagDesktopMain extends Application {

    public TrayManager systemTray;
    private MainView mainView;
    private FileTaggingDialog fileTaggingDialog;

    @Override
    public void init() throws Exception {
        this.systemTray = TrayManager.getInstance();
        this.mainView = SpringContextUtil.getContext().getBean(MainView.class).init(new BorderPane());
    }

    @Override
    public void start(Stage beginStage) throws IOException {
        beginStage.setTitle("faifaiTag");
        Scene scene = new Scene(mainView.getRoot(), 800, 500);
        beginStage.setScene(scene);
        StageManager.getInstance().registerStage("MainStage", beginStage);
        StageManager.getInstance().addCloseListener(new StageCloseListener());
        beginStage.show();
    }

    @Override
    public void stop(){
        log.info("关闭faifaiTag");
        // 清理虚拟线程
        VirtualThreadPoolManager.shutdownAll();
    }
}
